package kr.hkit.powerjava.chapter22.work;

import java.util.ArrayList;
import java.util.StringTokenizer;

import javax.swing.JOptionPane;

public class Test {
	public static void main(String[] args) {
		ArrayList<Department> deptList = new ArrayList<>();
		DepartmentDAO deptDao = new DepartmentDAO(deptList);
		
		deptDao.addItem(new Department(1,"컴공",4));
		deptDao.prnList();
		
		
		/*
		ArrayList<Student> stdList = new ArrayList<>();
		StudentManager sm = new StudentManager(stdList);
		Student std = null;
		int res = 0;
		initlist(stdList);

		do {
			System.out.println("메뉴 선택");
			// trycatch
			try {
				res = Integer.parseInt(JOptionPane
						.showInputDialog("1.추가 2.검색 3.수정 4.삭제 5.리스트 6. 종료"));
			} catch (NumberFormatException e) {
				res = 6;
			}
			switch (res) {
				case 1:// 추가
					std = inputInfo(true);
					sm.addItem(std);
					break;
				case 2:// 검색
					std = inputInfo(false);
					std = sm.searchitem(std);
					if (std == null) {
						System.out.println("해당학생 음슴");
					} else {
						System.out.println(std);
						// JOptionPane.showMessageDialog(null, std);
					}
					break;
				case 3:// 수정
					std = inputInfo(true);
					sm.setitem(std);
					
					break;
				case 4:// 삭제
					std = inputInfo(false);
					sm.delitem(std);
					break;
				case 5:// 리스트
					sm.prnList();
					break;
				default:// 종료
					break;
			}

		} while (res < 6);*/
	}

	private static Student inputInfo(boolean b) {
		if (b == true) {
			String std = JOptionPane.showInputDialog("학번 성명 국어 영어 수학");
			StringTokenizer s = new StringTokenizer(std);
			int stdNum = Integer.parseInt(s.nextToken());
			String stdName = s.nextToken();
			int kor = Integer.parseInt(s.nextToken());
			int eng = Integer.parseInt(s.nextToken());
			int math = Integer.parseInt(s.nextToken());
			return new Student(stdNum, stdName, kor, eng, math);
		} else {
			String std = JOptionPane.showInputDialog("학번 성명");
			StringTokenizer s = new StringTokenizer(std);
			int stdNum = Integer.parseInt(s.nextToken());
			String stdName = s.nextToken();
			return new Student(stdNum, stdName);
		}

	}

	private static void initlist(ArrayList<Student> stdList) {		//레퍼런스
		stdList.add(new Student(1, "김태희", 87, 87, 87));
		stdList.add(new Student(2, "이민정", 70, 70, 70));
		stdList.add(new Student(3, "이나영", 95, 88, 88));
		stdList.add(new Student(4, "임수정", 87, 86, 86));
		stdList.add(new Student(5, "장예원", 87, 97, 99));
		stdList.add(new Student(6, "장예원", 80, 97, 100));

	}
}
